package com.flower.core_service.config;

import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;
import reactor.core.Disposable;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * 监听服务的销毁与启动
 */
@Slf4j
@Component
class AppListenerSystem implements ApplicationRunner, Disposable, ApplicationListener<ContextClosedEvent> , ServletContextListener {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("程序启动");
    }

    @Override
    public void dispose() {
        log.info("程序销毁");
    }

    @Override
    public void onApplicationEvent(@NonNull ContextClosedEvent contextClosedEvent) {

        ApplicationContext applicationContext=contextClosedEvent.getApplicationContext();

    }

    public void contextInitialized(ServletContextEvent sce) {
        ServletContext servletContext=sce.getServletContext();

    }

    public void contextDestroyed(ServletContextEvent sce) {
    }
}
